﻿package mortal.game.view.shopMall.shopSecKilling
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.net.*;
    import mortal.component.gconst.*;
    import mortal.component.ui.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.activeTime.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class ShopSecKillingWin extends BaseWindow
    {
        private var _consumeBox:GConsumeBox;
        private var _doubleCountDown:SecTimerBitmapView;
        private var _rechargeBtn:GLoadingButton;
        private var _goodsList:GTileList;
        private var _leftTime:SecTimerView;
        private var _info:SPanicBuyMsg;
        private static var _instance:ShopSecKillingWin;

        public function ShopSecKillingWin(param1:ILayer = null)
        {
            super(param1);
            this.setSize(902, 562);
            this.title = Language.getString(35556);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ShopPanicBg, 8, 37, this));
            this.pushUIToDisposeVec(UIFactory.bg(600 - 13 + 80, 106, 145, 27, this, ImagesConst.ComboBg));
            this._consumeBox = UIFactory.gConsumeBox("", 607 + 50, 109, 0, this);
            this._consumeBox.addItem(ConsumeData.ShowMoneyType, EPriceUnit._EPriceUnitGold, 0, Language.getString(35557), "1");
            this._doubleCountDown = UIFactory.secTimerBitmapView(349, 179, "ShopSecKillingNumber.png", 27.9, 36, 0, this, 10);
            this._doubleCountDown.customCharIndex = {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, ::10};
            this._doubleCountDown.setParse("hh:mm:ss");
            this._doubleCountDown.timeOutHandler = this.activeEndHandler;
            this.pushUIToDisposeVec(UIFactory.bg(347, 196, 59, 2, this, ImagesConst.SplitLine3));
            this.pushUIToDisposeVec(UIFactory.bg(431, 196, 59, 2, this, ImagesConst.SplitLine3));
            this.pushUIToDisposeVec(UIFactory.bg(515, 196, 59, 2, this, ImagesConst.SplitLine3));
            this._rechargeBtn = UIFactory.gLoadingButton(ResFileConst.investmentRechargeBtn, 668, 52, 141, 43, this);
            this._rechargeBtn.configEventListener(MouseEvent.CLICK, this.rechargeHandler);
            this._goodsList = UIFactory.tileList(167 - 18, 253, 800, 480, this);
            this._goodsList.columnWidth = 119;
            this._goodsList.rowHeight = 104;
            this._goodsList.horizontalGap = 114;
            this._goodsList.verticalGap = 5;
            this._goodsList.setStyle("cellRenderer", SeckillingRender);
            var _loc_1:* = GlobalStyle.textFormatLv.center();
            _loc_1.size = 17;
            this._leftTime = UIFactory.secTimeView("hh:mm:ss", 445, 105, 200, 40, this, _loc_1);
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.timeOutHandler = this.getItemListLatter;
            this.getItemList();
            NetDispatcher.addCmdListener(ServerCommand.secKillingItemListUpdate, this.updateItemList);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.secKillingItemListUpdate, this.updateItemList);
            GameProxy.shop.closePanicBuyPanel();
            this._leftTime.dispose(param1);
            this._leftTime = null;
            this._consumeBox.dispose(param1);
            this._consumeBox = null;
            this._doubleCountDown.dispose(param1);
            this._doubleCountDown = null;
            this._rechargeBtn.dispose(param1);
            this._rechargeBtn = null;
            this._goodsList.dispose(param1);
            this._goodsList = null;
            this._info = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function updateItemList(param1:SPanicBuyMsg = null) : void
        {
            var _loc_4:SPanicBuyItemMsg = null;
            this._info = Cache.instance.secKilling.sPanicBuyMsg;
            var _loc_2:* = new DataProvider();
            var _loc_3:* = this._info.panicBuyItems;
            for each (_loc_4 in _loc_3)
            {
                
                _loc_2.addItem(_loc_4);
            }
            this._goodsList.dataProvider = _loc_2;
            return;
        }// end function

        private function updateNextActiveTime() : void
        {
            var _loc_1:* = ActiveTimeUtil.getSClientActive(EActiveType._EActiveTypeSecKilling);
            var _loc_2:* = _loc_1.startDt;
            var _loc_3:* = _loc_1.endDt;
            var _loc_4:* = ClockManager.instance.nowDate;
            if (_loc_4.time > _loc_2.time && _loc_4.time < _loc_3.time)
            {
                this._leftTime.stop();
                this._leftTime.text = Language.getString(35558);
                this._doubleCountDown.setLeftTime((_loc_3.time - _loc_4.time) * 0.001);
            }
            else if (_loc_4.time >= _loc_3.time)
            {
                this._leftTime.stop();
                this._leftTime.text = Language.getString(35559);
                this._doubleCountDown.setLeftTime(0);
                this._doubleCountDown.stop();
            }
            else
            {
                this._leftTime.setParse(Language.getString(35560));
                this._leftTime.setLeftTime((_loc_1.startDt.time - _loc_4.time) * 0.001);
                this._doubleCountDown.setLeftTime(0);
                this._doubleCountDown.stop();
            }
            return;
        }// end function

        private function rechargeHandler(event:MouseEvent) : void
        {
            GameUtil.gotoRecharge(ModuleTypeConst.SecKilling);
            return;
        }// end function

        private function activeEndHandler() : void
        {
            this.updateNextActiveTime();
            this.updateItemList();
            return;
        }// end function

        private function getItemList(param1:Object = null) : void
        {
            if (!this.isDisposed)
            {
                GameProxy.shop.getPanicBuyConfig();
                this.updateNextActiveTime();
            }
            return;
        }// end function

        private function getItemListLatter() : void
        {
            CallLater.setCallLater(this.getItemList, 2);
            return;
        }// end function

        public static function get instance() : ShopSecKillingWin
        {
            if (_instance == null)
            {
                _instance = new ShopSecKillingWin;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
